home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / utexec2.zip / RUN16.C < prev    next >
C/C++ Source or Header  |  1994-05-06  |  2KB  |  131 lines

  1. /* Freely given to the public domain by Timothy A. Anderson */
  2. /* Do what you want with it. */
  3.  
  4. #include <windows.h>
  5.  
  6. #define W32SUT_16
  7. #include <w32sut.h>
  8.  
  9. static HINSTANCE global_hinst;
  10.  
  11. typedef struct enum_info_struct {
  12.     HINSTANCE h_instance;
  13.     HWND h_wnd;
  14.     HTASK h_task;
  15. } enum_info_type;
  16.  
  17. static DWORD is_app_running(enum_info_type *p_info)
  18. {
  19.     if (p_info->h_wnd == NULL) {
  20.         return FALSE;
  21.     }
  22.     
  23.     if (!IsWindow(p_info->h_wnd) || !IsTask(p_info->h_task)) {
  24.         return FALSE;
  25.     }
  26.  
  27.     if (GetWindowWord(p_info->h_wnd, GWW_HINSTANCE) != p_info->h_instance) {
  28.         return FALSE;
  29.     }
  30.  
  31.     if (GetWindowTask(p_info->h_wnd) != p_info->h_task) {
  32.         return FALSE;
  33.     }
  34.  
  35.     return TRUE;
  36.  
  37. }
  38.  
  39. static int PASCAL enum_wnd_proc(HWND h_wnd, DWORD l_param)
  40. {
  41.     HINSTANCE h_instance;
  42.     enum_info_type *p_enum_info;
  43.     
  44.     h_instance = GetWindowWord(h_wnd, GWW_HINSTANCE);
  45.     p_enum_info = (enum_info_type  *)l_param;
  46.     
  47.     if (h_instance == p_enum_info->h_instance) {
  48.         p_enum_info->h_wnd = h_wnd;
  49.         return FALSE;
  50.     }
  51.     return TRUE;
  52. }
  53.  
  54. DWORD __export PASCAL RunThunkInit(UT16CBPROC pfnCB, LPVOID data)
  55. {
  56.     return(TRUE);
  57. }
  58.  
  59. typedef struct run_thunk_data_struct {
  60.     char *p_exec;
  61.     char *p_data;
  62. } run_thunk_data_type;
  63.  
  64. DWORD __export PASCAL RunThunkRun(LPVOID pData, DWORD funcode)
  65. {
  66.     run_thunk_data_type *p_thunk_data;
  67.     enum_info_type *p_enum_info;
  68.  
  69.     FARPROC fp;
  70.     UINT rval;
  71.  
  72.     switch(funcode) {
  73.     case 0:
  74.         return(sizeof(enum_info_type));
  75.         break;
  76.     
  77.     case 1:
  78.         p_thunk_data = (run_thunk_data_type *)pData;
  79.         
  80.         rval = WinExec(p_thunk_data->p_exec, SW_SHOW);
  81.         p_enum_info = (enum_info_type *)p_thunk_data->p_data;
  82.  
  83.         p_enum_info->h_wnd  = NULL;
  84.         p_enum_info->h_task = NULL;
  85.  
  86.         if (rval < 32) {
  87.             p_enum_info->h_instance = NULL;
  88.         } else {
  89.             p_enum_info->h_instance = (HINSTANCE)rval;
  90.  
  91.             fp = MakeProcInstance(enum_wnd_proc, global_hinst);
  92.             EnumWindows(fp, (DWORD)p_enum_info);
  93.             FreeProcInstance(fp);
  94.             
  95.             if (p_enum_info->h_wnd != NULL) {
  96.                 p_enum_info->h_task = GetWindowTask(p_enum_info->h_wnd);
  97.             }
  98.  
  99.         }
  100.         return((DWORD)rval);
  101.         break;
  102.  
  103.     case 2:
  104.         return(is_app_running((enum_info_type *)pData));
  105.         break;
  106.                 
  107.     }
  108.  
  109.     return(0);
  110.             
  111. }
  112.  
  113. int CALLBACK LibMain(HINSTANCE hInst,
  114.     WORD wDataSeg,
  115.     WORD cbHeapSize,
  116.     LPSTR lpszCmdLine)
  117. {
  118.     if (cbHeapSize) {
  119.         UnlockData(0);
  120.     }
  121.     global_hinst = hInst;
  122.     
  123.     return(TRUE);
  124. }
  125.  
  126. int CALLBACK WEP(int nParameter)
  127. {
  128.     return(TRUE);
  129. }
  130.  
  131.